﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace safehomeSimulation
{
    public class coreSys
    {
        private bool HighTemperature;
        private string Temperature;
        private bool HighWet;
        private string Wet;
        private bool HighSmoke;
        private string Smoke;
        private bool HighCO;
        private string CO;

        private List<Msg> _msgs = new List<Msg>();
        private Msg _msg = new Msg();


        public void ProcessMsg(List<Msg> MsgInRoom)
        {
            foreach (Msg one in MsgInRoom)
            {

                switch (one.MId)
                {
                    case utility.ExceptionType.TypeNormal:

                        break;
                    case utility.ExceptionType.TypeCO:
                        CO = one.ParaMessage;
                        HighCO = true;
                        break;
                    case utility.ExceptionType.TypeSmoke:
                        Smoke = one.ParaMessage;
                        HighSmoke = true;
                        break;
                    case utility.ExceptionType.TypeTemperature:
                        Temperature = one.ParaMessage;
                        HighTemperature = true;
                        break;
                    case utility.ExceptionType.TypeWet:
                        Wet = one.ParaMessage;
                        HighWet = true;
                        break;

                }
                if (HighTemperature && HighSmoke)
                {
                    
                    _msg.MId = utility.ExceptionType.FireDisaster;
                    _msg.ParaMessage = Temperature + "\n" + Smoke;
                    _msg.location = one.location;
                    _msg.ProcessMessage = "Fire !!!";
                    _msgs.Add(_msg);
                }
                if (HighCO)
                {
                    _msg.MId = utility.ExceptionType.CODisaster;
                    _msg.ParaMessage = CO;
                    _msg.location = one.location;
                    _msg.ProcessMessage = "CO density is too high !!!";
                    _msgs.Add(_msg);
                }
                if (HighWet)
                {
                    _msg.MId = utility.ExceptionType.WaterDisaster;
                    _msg.ParaMessage = Wet;
                    _msg.location = one.location;
                    _msg.ProcessMessage = "Wet level is too high !!!";
                    _msgs.Add(_msg);
                }


            }
        }

        public Msg GetCoreMsg()
        {
            return _msg;
        }
        public List<Msg> GetCoreAllMsg()
        {
            return _msgs;
        }
    }
}
